'use strict';

import React,{Component}from 'react';

import RootSiblings from 'react-native-root-siblings'
import SpinContainer from './SpinContainer';

export default class Spin extends React.Component {

    static displayName = 'Spin';
    static propTypes = SpinContainer.propTypes;

    static show = (options) => {

        return new RootSiblings(
            <SpinContainer
                {...options}
                visible={true}
            />
        );
    };

    static hide = (sibling) => {
        if (sibling instanceof RootSiblings) {
            sibling.destroy();
        } else {
            console.warn(`Spin.hide expected a \`RootSiblings\` instance as argument.\nBut got \`${typeof sibling}\` instead.`);
        }
    };

    _spin = null;

    constructor(props) {
        super(props);
    };

    componentDidMount = () => {
        this._spin = new RootSiblings(
            <SpinContainer
                {...this.props}
            />
        );
    };

    componentDidUpdate(){
        this._spin.update(
            <SpinContainer
                {...this.props}
            />
        );
    }

    componentWillUnmount = () => {
        this._spin.destroy();
    };

    render(){
        return null;
    }
}


